<?php
//date range
$date_range = BUtils::GetDateRangeString(strtotime($rows[0]['start_date']), strtotime($rows[0]['end_date']));

$date_array = $reach_array = $clicks_array = $notifications_array = $spread_array = $redeems_array = array();
$i = $j = $reach = $clicks = $notifications = $spread = $redeems = 0;

$no_data = array('reach'=>0, 'clicks'=>0, 'notifications'=>0, 'redeems'=>0);
$continue_ts = $rows[$i]['ts_local_date'];
foreach ($rows as $k => $r) {
	$date_array[] = date('d.m', $r['ts_local_date']);
	$clicks_array[] = $clicks += $r['clicks'];
	$notifications_array[] = $notifications += $r['notifications'];
	$spread_array[] = $spread += $r['spread'];
	$redeems_array[] = $redeems += $r['redeems'];
	$reach_array[] = $reach += $r['reach'];
}
?>
<div id="chart" style="width:800px; height:600px; margin:0 auto"></div>
<script type="text/javascript">
$(function() {
	$('#chart').highcharts({
		chart: {
			type: 'line',
			marginRight: 130,
            marginBottom: 25
		},
		title: {
			text: '<?php echo BUtils::T('special_report_title_lbl'); ?>',
			x: -20 //center
		},
		subtitle: {
			text: '<?php echo $date_range; ?>',
			x: -20
		},
		xAxis: {
			categories: <?php echo json_encode($date_array, true); ?>,
			type: 'datetime',
			tickInterval: 7
		},
		yAxis: {
			min: -5,
			title: {
				text: '<?php echo BUtils::T('special_report_yaxis_lbl'); ?>'
			},
			allowDecimals: false,
			plotLines: [{
				value: 10,
				width: 2,
				color: '#00aaee'
			}]
		},
		tooltip: {
			valueSuffix: ''
		},
		legend: {
			layout: 'vertical',
			align: 'right',
			verticalAlign: 'top',
			x: -10,
			y: 100,
			borderWidth: 0
		},
		series: [{
			name: 'Reach',
			data: <?php echo json_encode($reach_array, true); ?>
		}, {
			name: 'Clicks',
			data: <?php echo json_encode($clicks_array, true); ?>
		}, {
			name: 'Notifications',
			data: <?php echo json_encode($notifications_array, true); ?>
		}, {
			name: 'Redeems',
			data: <?php echo json_encode($redeems_array, true); ?>
		}]
	});
});
</script>